package com.manugomezmq.MeetTheCity;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;

public class MeetTheCity extends Activity {
	
	private static final int RESULT_FINISH = 99;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
    
    // MENU OPTIONS
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
	    MenuInflater inflater = getMenuInflater();
	    inflater.inflate(R.menu.menu_gen, menu);
	    return true; 
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
	    // Handle item selection
	    switch (item.getItemId()) {
	    case R.id.menu_about:
	        
			String strVersion;

			PackageInfo packageInfo;
			try {
				packageInfo = getPackageManager().getPackageInfo(
						getPackageName(), 0);
				strVersion = getResources().getString(R.string.app_name) + "\n"
							+ packageInfo.versionName + "\n";
			} catch (NameNotFoundException e) {
				strVersion = getResources().getString(R.string.version_notload);
			}

			new AlertDialog.Builder(this).setTitle(getResources().getString(R.string.menu_about)).setMessage(strVersion)
					.setPositiveButton("OK",
					new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int which) {
						}
					}).show();
	    	  
	        return true;
	        
	    case R.id.menu_quit:
        	android.os.Process.killProcess( android.os.Process.myPid());
        	finish();
	        return true;
	        
	    default:
	        return super.onOptionsItemSelected(item);
	    }
	}
	
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
        super.onActivityResult(requestCode, resultCode, intent);
        if (resultCode == RESULT_FINISH) {
        	android.os.Process.killProcess( android.os.Process.myPid());
        	finish();
        }
    }
}